function getChartData() {
}

$(document).on('click', 'a.accordion-toggle', function(e) {
    $(e.target).parent().siblings('.accordion-body').on('hidden', function(e) {
        e.stopPropagation();
    });
});

function gettableData() {
	var request = $.ajax({
		type: "GET",
		url: "/ajax/get-Tablebids/",
		dataType: 'json',
		data: {
			'course_num': window.bidit_globals.g_currCourseProfile
		},
		success: function(data) {
			var chardata = new google.visualization.DataTable();

			chardata.addColumn('string', 'group');
			chardata.addColumn('number', 'available');
			chardata.addColumn('number', 'accepted');
			chardata.addColumn('number', 'declined');
			chardata.addColumn('number', 'bidding points');
			chardata.addRows(data);


			var table = new google.visualization.Table(document.getElementById('table_div'));
			table.draw(chardata, {
				showRowNumber: true
			});

		}
	});


}




function getTableData2() {
	var request = $.ajax({
		type: "GET",
		url: "/ajax/get-tablebids2/",
		dataType: 'json',
		data: {
			'university': window.bidit_globals.g_currUniversity,
			'department': window.bidit_globals.g_currChosenInfoBtnDepart,
			'course_num': window.bidit_globals.g_currCourseProfile
		},
		success: function(data) {
			$('#table_table').empty();

			if(Object.keys(data).length==0){
				$('#statisticsBtnGroup').addClass('hide');
				$('#bid-row-title').addClass('hide');
				$('#chart_div').addClass('hide');
				$('#statistcsError').removeClass('hide');

			}
			else{
				$('#statistcsError').addClass('hide');
				$('#statisticsBtnGroup').removeClass('hide');
				$('#bid-row-title').removeClass('hide');
				$('#table_div').removeClass('hide');
			
				var graphData = [['קבוצה', 'אחוזי ביקוש']]

				var sortedKeys=[];
				for (keys in data){
					sortedKeys.push(keys);
				}

				sortedKeys.sort(function(a,b){return (b-3*(b%10)) - (a-3*(a%10))})
				//sortedKeys.reverse();
				for (var j=0;j<sortedKeys.length;j++){
					var bid_semester = sortedKeys[j];
					// $('<div id="'+bid_semester+'"></div>').appendTo('#table_table');
					var temp =Number(bid_semester);
					temp=(temp - (temp%10))/10;
					var year =temp;
					var syear = String(year);
					var semester="-";
					if(Number(bid_semester)%10==1){
						semester="א";

					}
					if(Number(bid_semester)%10==2){
						semester="ב";
					}
					var bid_groups=(data[bid_semester])[1];
					var addTo;
					var currGroupID;
					var gotFirst00= false;

					for (var i=0;i<bid_groups.length ;i++){
						// debugger;
						var bid_group = bid_groups[i]
						var lectureKind;
						var minpoints =bid_group.min_accept_points;


						currGroupID="data"+syear+semester;
						if(bid_group.gNum=='00'){
							lectureKind="bid-row-lesson";
							// currGroupID=syear+semester;
							// addTo = "table_table";
							// gotFirst00= true;
							$('<div id="bid-ag' + syear + semester +'" class="accordion-group"><div class="accordion-heading"><a id="parent'+syear+semester +'" class="accordion-toggle" data-toggle="collapse" data-parent="#table_table" href="#data'+syear+semester +'"></a></div></div>').appendTo('#table_table');

							
							
						}
						else{
							lectureKind="bid-row-default ";
							addTo = currGroupID;

						}
						if(bid_group.gNum == '00'){
							// debugger;
							var requestPrecenage=0;
							if(bid_group.places!=0){
								requestPrecenage = Math.round((100/Number(bid_group.places))*Number(bid_group.requested));
							}
							var graphDataRow=[String(year)+' '+semester,requestPrecenage];
							graphData.push(graphDataRow);
							minpoints='';

						}

						// if(gotFirst00==false){
						// 	addTo = "table_table";
						// }

						if(bid_group.gNum=='00'){
							addTo ="parent"+syear+semester;
							$('<div id="' + currGroupID +'" class="accordion-body collapse"><div id="inner'+syear+semester+'" class="accordion-inner"></div></div>').appendTo('#bid-ag' + syear + semester);
						}
						else{
							addTo = 'inner'+syear+semester;
						}

						$('<div id="'+bid_semester+bid_group.gNum+'" class="row-fluid '+lectureKind+' " data-cGroup="'+currGroupID+'" >' +
								'<div class="span1" style="font-weight:bold;">'+minpoints+'</div>' 	+
								// '<div class="span1">'+bid_group.max_points+'</div>' 	+
								// '<div class="span1">'+bid_group.rejected_neto+'</div>' 	+
								'<div class="span1">'+bid_group.rejected+'</div>' 	+
								'<div class="span1">'+bid_group.accepted+'</div>' 	+
								'<div class="span1">'+bid_group.requested+'</div>' 	+
								'<div class="span1">'+bid_group.places+'</div>' 	+
								'<div class="span3">'+bid_group.lecturer+'</div>'	 	+
								'<div class="span1">'+bid_group.gNum+'</div>'	 	+
								'<div class="span1">'+semester+'</div>'	 	+
								'<div class="span2">'+year+'</div>'	 	+
						'</div>').appendTo('#' + addTo);
					}

				}


				var chartData = google.visualization.arrayToDataTable(graphData);

				var options = {
						height:200,	
						width:600,	
						legend: {position: 'none'},
						vAxis: {minValue: 0},
						hAxis: {direction: -1}
						/*
						vAxis: {
							minValue: 0,
							title: 'סטודנטים',

							titleTextStyle: {
								color: 'red'
							}
						},
						*/
						// colors: ['#3366cc', '#109618', '#dc3912', '#ff9900']
				};


				var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
				chart.draw(chartData, options);

			}
		}, //success
		error: function(){

			//d$('#statisticsBtnGroup').addClass('hide');
			//d$('#bid-row-title').addClass('hide');
			//d$('#table_div').addClass('hide');
			//d$('#statistcsError').removeClass('hide');
		} 

	});
}






